<?php
// https://github.com/videlalvaro/php-amqplib
require_once __DIR__.'/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;

$connect = new AMQPStreamConnection('192.168.205.128', 5672, 'admin', '123456');
$channel = $connect->channel();

$channel->exchange_declare('tell_everybody', 'fanout', false, false, false);

// 私有化队列
list($queueName, ,) = $channel->queue_declare('', false, false, true, false);

$channel->queue_bind($queueName, 'tell_everybody');

echo ' [*] Waiting for To exit press CTRL+C'.PHP_EOL;

$callbackFunction = function ($msg) {
    echo "[x] ".$msg->body.PHP_EOL;
};

$channel->basic_consume($queueName, '', false, true, false, false, $callbackFunction);

while (count($channel->callbacks)) {
    $channel->wait();
}

$channel->close();
$connect->close();
